﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;
using MsDAL;
using System.ComponentModel;
using Components;

namespace ServiceHelper
{
    [DataObjectAttribute]
    public partial class Bas1a10Manager : Bas1a10Base
    {
        Bas1a10DAL dal = new Bas1a10DAL();

        private static Bas1a10Manager _entity;

        public static Bas1a10Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Bas1a10Manager();
                return _entity;
            }
        }

        #region 个人代码
        public string SaveData(Hashtable tb, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            Bas1a10 model = null;
            if ("A" == action)
            {
                model = new Bas1a10();
                CommonUtil.GetInstance.CopyProperties(tb, model);

                model.Usercode = Context.GetAppByUserCode(usercode);
                model.Listid = Sys0a60Manager.Entity.CreateSn("bas1a10_listid", usercode);

                //查询状态，默认为1
                Bas0a00 statusModel = Bas0a00Manager.Entity.GetModelById(1);
                if (statusModel == null) return "当前系统常量未设置，请联系管理员！";
                model.Status = 1;
                model.Balance = model.Startamount;

                lst.Add(this.Add(model));
            }
            else if ("M" == action)
            {
                model = this.GetModelById(Validation.ToString(tb["listid"]));
                var beforeAmout = model.Startamount;
                CommonUtil.GetInstance.CopyProperties(tb, model);

                model.Balance = model.Balance - beforeAmout + model.Startamount;

                lst.Add(this.Update(model));
            }
            else if ("D" == action)
            {
                lst.Add(dal.DeleteModel(Validation.ToString(tb["listid"])));
            }

            return CommonManager.Entity.SaveData(lst);
        }

        #endregion

        public SqlApp UpdateBalance(string sellerid, decimal amout)
        {
            return bas1a10Dal.UpdateBalance(sellerid, amout);
        }
    }
}



